//app.js

App({
  onLaunch: function() {
    wx.showShareMenu()
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  addRec: (num1,num2) => {
    return num1+num2
  },
  formatDateTime: inputTime => {
    var date = new Date(inputTime * 1000);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  },
  timeLag: time => {
    let h = parseInt(time / 3600)
    let m = parseInt(((time % (3600 * 24)) % 3600) / 60)
    let d = parseInt(time % 60)
    if (h <= 9) {
      h = '0' + h
    }
    if (m <= 9) {
      m = '0' + m
    }
    if (d <= 9) {
      d = '0' + d
    }
    return h + ':' + m + ':' + d;
  },
  getTime: orderTime => {
    if (orderTime < 1000) {
      return orderTime.toFixed(0) + 'm';
    } else if (orderTime > 1000) {
      return (orderTime / 1000).toFixed(1) + 'km';
    }
  },
  globalData: {
    userInfo: null,
    token: '',
    requireHttps: 'https://cw.90buluo.com',
    APP_SECRET: '129030b2307e99c58838e1b3503840e0',
    APP_ID: 'wx2016a8d6b87deff0',
    openid: '',
    session_key: '',
    unionid: '',
    service_call: '',
    money: '',
    balance: '',
    allMoney: '',
    timeStamp: '',
    nonceStr: '',
    package: '',
    paySign: '',
    cashMoney: '',
    viewShow: '',
    garageid: '',
    address: '',
    usable: '',
    name: '',
    juli: '',
    parkingid: '',
    describe: '',
    card: [],
    gid: '',
    is_show: '',
    g_address: '',
    g_name: '',
    juli: '',
    g_usable: '',
    g_id: '',
    userHead: '',
    userName: '',
    codeImgPath: '',
    sex: '',
    audit_status: '',
    latitude: '',
    longitude: '',
    updateId: '',
    auditStatus: ''
  },

})